<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>收藏夹</title>
<%@ include file="/page/wx/include.jsp"%>
<script type="text/javascript" src="<%=basePath%>/statics/plugins/layer/layer.js"></script>
<script type="text/javascript">
    $(function() {
        $('.bjd_list1_con ul li i').click(function() {
            $(this).toggleClass('current');
        });
    });
</script>
<style>
.fl_nav1 {
    top: 0
}

.cart_bottom2 {
    bottom: 0;
}

.pp_box {
    top: 0.78rem;
}

.bjd_list1_con ul li {
    position: relative
}

.bjd_list1_con ul li i {
    position: absolute;
    cursor: pointer;
    left: 0.25rem;
    top: 50%;
    width: .36rem;
    height: .36rem;
    margin-top: -.18rem;
    background: url('<%=basePath%>/statics_wx/images/icon-q1.png') no-repeat;
    background-size: .35rem .35rem;
}

.bjd_list1_con ul li i.current {
    background: url('<%=basePath%>/statics_wx/images/icon-q2.png') no-repeat;
    background-size: .35rem .35rem
}

.bjd_list1_con ul li .box4 {
    margin-left: .82rem;
}
</style>
</head>
<body style="background:#f5f5f5">

    <c:choose>
        <c:when test="${favoriteCount == 0 }">
            <div class="noresult">
                <p>
                    <i><img src="<%=basePath%>/statics_wx/images/icon_nofav.png" /></i>
                    <span>您还没有收藏商品哦~</span>
                </p>
            </div>
        </c:when>
        <c:otherwise>
            <div class="headerfixed"></div>
            <div class="fl_nav1" style="top:0px;">
                <strong>已收藏${favoriteCount }个商品</strong>
                <b>
                    <a href="${rootPath }/wx/favorite/toFavoritePage">完成</a>
                </b>
            </div>
            <div class="bjd_list1">
                <div class="bjd_list1">
                    <div class="bjd_list1_con">
                        <ul>
                        <c:forEach items="${favoriteList }" var="favorite" varStatus="i">
                            <c:set var="intNum" value="${fn:substringBefore(favorite.productPrice, '.') }"></c:set>
                            <c:set var="smallNum" value="${fn:substringAfter(favorite.productPrice, '.') }"></c:set>
                            <c:if test="${smallNum == '0000' }">
                                <c:set var="smallNum" value="00"></c:set>
                            </c:if>
                            <li><i title="${favorite.id}"></i>
                                <div class="box4">
                                    <div class="pic">
                                        <img src="${imgRootURL }${favorite.productImg}${ossImgZoomWX}" 
                                            onerror="this.src='<%=basePath%>/statics/images/default.jpg';"
                                            onclick="javascript: doProductDetail('${favorite.productId}');">
                                    </div>
                                    <div class="item-info">
                                        <h2 onclick="javascript: doProductDetail('${favorite.productId}');">
                                            <c:choose>
                                                <c:when test="${fn:length(favorite.productName) >= 50 }">
                                                    ${fn:substring(favorite.productName, 0, 50) }...
                                                </c:when>
                                                <c:otherwise>
                                                    ${favorite.productName}
                                                </c:otherwise>
                                            </c:choose>
                                        </h2>
                                        <h3 style="z-index: 90; background: white;">
                                            <strong>¥
                                                <em>${intNum }.</em>${smallNum }
                                            </strong>
                                        </h3>
                                    </div>
                                </div>
                            </li>
                        </c:forEach>
                    </ul>
                    </div>
                </div>
            </div>
            <div class="footerfixed2"></div>
            <div class="cart_bottom2" style="z-index: 95;">
                        <div class="cart_bottom2_con">
                            <label><i id="allLi" onclick="javascript: doAllCheck();"></i><span>全选</span></label>
                            <b><a href="#" onclick="javascript: doDelFavorite();" class="btn3 a11">取消收藏</a>
                            </b>
                        </div>
                    </div>
        </c:otherwise>
    </c:choose>

<jsp:include page="../../wx_footer.jsp" />
<script type="text/javascript">

function doAllCheck() {
    $(".bjd_list1_con ul li i").removeClass('current');
    //$(".bjd_list1_con ul li i").toggleClass('current');
    $("#allLi").toggleClass('current');
    var className = $("#allLi").attr("class");
    $(".bjd_list1_con ul li i").addClass(className);
}

/**
 * 查看商品详情
 */
function doProductDetail(productId) {
    window.location.href = '<%=basePath%>/wx/product/detail?productId=' + productId;
}

/**
 * 取消收藏（批量）
 */
function doDelFavorite() {
    var liArr = $("i.current");
    if(liArr && liArr.length > 0) {
        var idArrStr = '';
        for(var i = 0; i < liArr.length; i ++) {
            if(liArr[i].title) {
                idArrStr += liArr[i].title + ',';
            }
        }
        if(idArrStr) {
            $.ajax({
                type : "post",
                url : rootPath + '/wx/favorite/doDelFavorite',
                data : {
                    idArrStr : idArrStr
                },
                async : false,
                datatype : "json",
                success : function(json) {
                    if (json.code == '1') {
                        layer.msg(json.msg,function() {
                            window.location.href = '<%=basePath%>/wx/favorite/toFavoriteEditPage';
                        },{time:2000});
                    } else {
                        layer.msg(json.msg,{time:3000});
                    }
                },
                error : function() {
                    layer.msg('暂时无法取消收藏',{time:1000});
                }
            });
        } else {
            layer.msg('请先选择商品',{time:1000});
        }
    } else {
        layer.msg('请先选择商品',{time:1000});
    }


}

</script>
</body>
</html>